package com.edu.java.spring.tutorial;

import java.util.Set;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.type.filter.AssignableTypeFilter;

public class Principal {

	public static void main(String[] args) throws ClassNotFoundException {
		/*
		 * ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addIncludeFilter(new AssignableTypeFilter(MyClass.class));

// scan in org.example.package
Set<BeanDefinition> components = provider.findCandidateComponents("org/example/package");
for (BeanDefinition component : components)
{
    Class cls = Class.forName(component.getBeanClassName());
    // use class cls found
     * 
     * MyClass aux = cls.newInstance();
boolean[] b = new boolean[10];
aux.getMatricula();
}
		 */
		ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
		provider.addIncludeFilter(new AssignableTypeFilter(Hello.class));
		Set<BeanDefinition> components = provider.findCandidateComponents("com.edu.java.spring.tutorial");

		for(BeanDefinition component : components){

			Class cls = Class.forName(component.getBeanClassName());
			try {
				Hello aux = (Hello) cls.newInstance();
				System.out.println("" + component);
			} catch (InstantiationException | IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
